#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

const int N = 2e5 + 5, inf = 0x3f3f3f3f, bit = 31;
int n, v;
long long ans;
int ch[2][N * bit], tot;

inline void insert(int a) {
  int cur = 0, c;
  for (int i = bit - 1; ~i; --i) {
    c = (a >> i) & 1;
    if (!ch[c][cur]) ch[c][cur] = ++tot;
    cur = ch[c][cur];
  }
}

int find(int r1, int r2, int dep) {
  if (!~dep) return 0;
  int a1 = -1, a2 = -1;
  if (ch[0][r1] && ch[0][r2]) a1 = find(ch[0][r1], ch[0][r2], dep - 1);
  if (ch[1][r1] && ch[1][r2]) a2 = find(ch[1][r1], ch[1][r2], dep - 1);
  if (~a1 || ~a2) return std::min(~a1 ? a1 : inf, ~a2 ? a2 : inf);
  if (ch[1][r1] && ch[0][r2])
    a1 = find(ch[1][r1], ch[0][r2], dep - 1) + (1 << dep);
  if (ch[0][r1] && ch[1][r2])
    a2 = find(ch[0][r1], ch[1][r2], dep - 1) + (1 << dep);
  return std::min(~a1 ? a1 : inf, ~a2 ? a2 : inf);
}

void dfs(int cur, int dep) {
  if (!~dep) return;
  if (ch[0][cur] && ch[1][cur])
    ans += find(ch[0][cur], ch[1][cur], dep - 1) + (1ll << dep);
  if (ch[0][cur]) dfs(ch[0][cur], dep - 1);
  if (ch[1][cur]) dfs(ch[1][cur], dep - 1);
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF888G Xor-MST.in", "r", stdin);
  freopen("CF888G Xor-MST.out", "w", stdout);
#endif
#endif

  read(n);
  for (int i = 1, a; i <= n; i++) insert(read(a));
  dfs(0, bit - 1);
  printf("%lld\n", ans);
  return 0;
}